class EventEmitter {
  constructor() {
    this.subs = Object.create(null)
  }

  $on(eventType, handler) {
    this.subs[eventType] = this.subs[eventType] || []
    this.subs[eventType].push(handler)
  }

  $emit(eventType) {
    if (this.subs[eventType]) {
      this.subs[eventType].forEach(handler => {
        handler();
      });
    }
  }
}

let em = new EventEmitter();

em.$on('click', () => { console.log(1) })
em.$on('click', () => { console.log(2) })

em.$emit('click')